﻿using Cinch;
using FR.SAFTAnalyserLite.Model;
using FR.SAFTAnalyserLite.Services;
using FR.SAFTAnalyserLite.ViewModels.Pane;
using MEFedMVVM.Common;
using System;
using System.ComponentModel;
using System.ComponentModel.Composition;

namespace FR.SAFTAnalyserLite.ViewModels
{
    public class HeaderViewModel : DocumentPartViewModel
    {
        public HeaderViewModel()
            : base("Cabeçalho")
        {
            if (!Designer.IsInDesignMode)
            {
                Mediator.Instance.Register(this);
            }
        }

        internal override void ResetSaftFile()
        {
            this.Cabecalho = null;
        }

        [MediatorMessageSink(MessageType.SAFT_FILE_OPENED)]
        private void LoadHeader(AuditFile saft)
        {
            this.Cabecalho = saft.Header;
        }

        Header cabecalho;
        public Header Cabecalho
        {
            get
            {
                if (cabecalho == null && SAFT.SaftAnalyser.Instance.SaftFile != null)
                    cabecalho = SAFT.SaftAnalyser.Instance.SaftFile.Header;
                return cabecalho;
            }
            set
            {
                cabecalho = value;
                NotifyPropertyChanged(ObservableHelper.CreateArgs<HeaderViewModel>(x => x.Cabecalho));
            }
        }

        //public string Pais
        //{
        //    get
        //    {
        //        if (this.Cabecalho != null && this.Cabecalho.CompanyAddress != null)
        //        {
        //            if (this.Cabecalho.CompanyAddress.Country is System.Xml.XmlNode[])
        //            {
        //                System.Xml.XmlNode[] nodes = this.Cabecalho.CompanyAddress.Country as System.Xml.XmlNode[];
        //                if (nodes != null && nodes.Length > 0)
        //                    return (this.Cabecalho.CompanyAddress.Country as System.Xml.XmlNode[])[0].InnerText;
        //            }
        //            else if (this.Cabecalho.CompanyAddress.Country != null)
        //                return this.Cabecalho.CompanyAddress.Country.ToString();
        //        }
        //        return "";
        //    }
        //    set { NotifyPropertyChanged(ObservableHelper.CreateArgs<HeaderViewModel>(x => x.Pais)); }
        //}
    }
}
